package tests;

import common.Utils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import java.io.IOException;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:DELL
 * Date:2025-03-29
 * Time:17:46
 */
public class SessionPage extends Utils {
    public static String url="http://127.0.0.1:8080/client.html";
    public SessionPage() {
        super(url);
    }
    //进入会话页成功
    public void SessionPageRight() throws IOException, InterruptedException {
        //聊天页表
        driver.findElement(By.cssSelector("body > div.client-container > div > div.left > div.tab > div.tab-session"));
        //用户名
        String expect="zhangsan";
        String res=driver.findElement(By.cssSelector("body > div.client-container > div > div.left > div.user")).getText();
        assert res.equals(expect);
        //好友列表
        driver.findElement(By.cssSelector("body > div.client-container > div > div.left > div.tab > div.tab-friend"));
        //搜索框
        driver.findElement(By.cssSelector("body > div.client-container > div > div.left > div.search > input[type=text]"));
        //搜索按钮
        driver.findElement(By.cssSelector("body > div.client-container > div > div.left > div.search > button"));
        //聊天的某一个用户
        driver.findElement(By.cssSelector("#session-list > li.selected"));
        //消息列表
        driver.findElement(By.cssSelector("#session-list"));
        //联系人列表
        driver.findElement(By.cssSelector("#friend-list"));
        Thread.sleep(3000);
        getScreenShot(getClass().getName());
        Thread.sleep(3000);
    }
    //点击消息，右侧会话框能正常显示该消息详细信息
    public void SessionList() throws InterruptedException, IOException {
        //点击消息列表标签页
        driver.findElement(By.cssSelector("body > div.client-container > div > div.left > div.tab > div.tab-session")).click();
        //点击具体会话
        driver.findElement(By.cssSelector("#session-list > li:nth-child(1)>h3")).click();
        Thread.sleep(3000);
        //消息列表
        driver.findElement(By.cssSelector("#session-list"));
        Thread.sleep(3000);
        //遍历每条消息,记录最新消息的用户和消息
        List<WebElement> nums=driver.findElements(By.cssSelector("#session-list->li"));
        if(nums.size()!= 0){
            String name= driver.findElement(By.cssSelector("#session-list > li.selected > h3")).getText();
            String text=driver.findElement(By.cssSelector("#session-list > li.selected > p")).getText();
            Thread.sleep(3000);
            //点击具体会话
            driver.findElement(By.cssSelector("#session-list > li:nth-child(1)>h3")).click();
            Thread.sleep(3000);
            //检查消息和用户名
            String nameA=driver.findElement(By.cssSelector("body > div.client-container > div > div.right > div.message-show > div:nth-child(5) > div > p")).getText();
            //验证最新一条消息
            assert nameA.equals(text);
            getScreenShot(getClass().getName());
            Thread.sleep(3000);
        }
    }
}
